var express = require('express');
var GenProject = require('./gen_project.js');
var router = express.Router();




/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', { title: 'Express' });
});


router.post('/api/genSimulation', async function (req, res, next) {
  let dataURL = req.body.dataURL
  let world_name = req.body.world_name
  console.log('world_name', world_name);
  let width = parseFloat(req.body.width)
  let height = parseFloat(req.body.height)
  let points = req.body.points
  let robots = req.body.robots

  let gp = new GenProject(world_name, width, height, points,robots, dataURL)
  await gp.writeWorld()
  await gp.writeModelConfig()
  await gp.writeModelSdf()
  await gp.writeTextures()
  await gp.writeMeshesMtl()
  await gp.writeMeshesObj()
  await gp.writeMeshesPng()
  await gp.writeLaunch()

  res.json({ msg: "ok" })
});


module.exports = router;
